package com.shenchuangit.tm.sdk.model;

import com.fasterxml.jackson.databind.JsonNode;
import com.shenchuangit.tm.sdk.TencentMeetingClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 会议管理接口
 *
 * @author FlyFive
 */
public class MeetingModel {
    public static final Logger logger = LoggerFactory.getLogger(MeetingModel.class);

    public MeetingModel() {
    }

    /**
     * 调用接口创建/预定一个会议
     *
     * @param requestBody 请求体
     * @return 创建会议结果
     */
    public String create(JsonNode requestBody) {
        String uri = "/v1/meetings";

        String result = TencentMeetingClient.getInstance().post(uri, requestBody);
        logger.info("创建会议：{}", result);

        return result;
    }

    /**
     * 调用接口修改会议
     *
     * @param meetingId   会议ID，腾讯会议接口返回的
     * @param requestBody 请求体
     * @return 修改会议结果
     */
    public String update(String meetingId, JsonNode requestBody) {
        String uri = "/v1/meetings/" + meetingId;

        String result = TencentMeetingClient.getInstance().put(uri, requestBody);
        logger.info("修改会议：{}", result);

        return result;
    }

    /**
     * 调用接口取消会议
     *
     * @param meetingId   会议ID，腾讯会议接口返回的
     * @param requestBody 请求体
     * @return 取消会议结果
     */
    public String cancel(String meetingId, JsonNode requestBody) {
        String uri = "/v1/meetings/" + meetingId + "/cancel";

        String result = TencentMeetingClient.getInstance().post(uri, requestBody);
        logger.info("取消会议：{}", result);

        return result;
    }

    /**
     * 获取某指定用户的会议列表
     *
     * @param userId     用户ID
     * @param instanceId 终端设备类型
     * @return 用户列表的字符串
     */
    public String queryByUser(String userId, int instanceId) {
        String uri = "/v1/meetings?userid=" + userId + "&instanceid=" + instanceId;

        String result = TencentMeetingClient.getInstance().get(uri);
        logger.info("获取用户ID={}的会议列表：{}", userId, result);
        return result;
    }

    /**
     * 通过会议 ID 查询会议详情
     *
     * @param meetingId  会议ID
     * @param userId     用户ID
     * @param instanceId 终端设备类型
     * @return 会议详情
     */
    public String queryById(String meetingId, String userId, int instanceId) {
        String uri = "/v1/meetings/" + meetingId + "?userid=" + userId + "&instanceid=" + instanceId;

        String result = TencentMeetingClient.getInstance().get(uri);
        logger.info("获取会议ID={}的会议详情：{}", meetingId, result);
        return result;
    }
}
